<template>
  <div id="dialogSort">
    <el-dialog
      class="about-set"
      title="设置投票数"
      :visible.sync="sortData.isShow"
      width="420px"
      :before-close="labelHandleClose"
    >
      <div class="form-box">
        <el-form
          ref="ruleForm"
          :rules="rules"
          :model="ruleForm"
          label-width="80px"
          class="demo-ruleForm"
          @submit.native.prevent
        >
          <el-form-item :label="nowCount" prop="voteCount">
            <el-input-number
              v-model="ruleForm.voteCount"
              size="mini"
              :min="1"
            ></el-input-number>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" plain @click="cancelLabel">取 消</el-button>
        <el-button type="success" @click="submitPass">确认</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { submitPassAPI } from '@/api/activeManagement/voteMaintain' // 接口
export default {
  name: 'DialogSort',
  msg: '投票维护-设置投票数',
  props: ['sortData'],
  data() {
    return {
      nowCount: '',
      ruleForm: {
        voteCount: ''
      },
      rules: {
        voteCount: [
          { required: true, message: '请选择投票数', trigger: 'blur' }
        ]
      }
    }
  },
  mounted() {
    this.id = this.sortData.params.id
    this.voteCount = this.sortData.params.voteCount
    this.nowCount = this.voteCount.toString()
  },
  methods: {
    // 点击确定
    submitPass() {
      let params = {
        voteCount: this.ruleForm.voteCount
      }
      submitPassAPI(
        this.id,
        params,
        (response) => {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$emit('refresh')
          this.sortData.isShow = false
        },

        (response) => {
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    labelHandleClose(done) {
      this.cancelLabel()
      done()
    },
    cancelLabel() {
      // 关闭前清空
      this.id = null
      this.sortData.voteCount = null
      this.sortData.isShow = false
    }
  }
}
</script>

<style lang="less">
// #dialogSort {
// }
</style>
